package com.warski.wonderfires.utils.task;

import com.warski.wonderfires.utils.BasicUtils;
import com.warski.wonderfires.utils.Logger;

/**
 * Created by xuhaiping on 2020/7/13.
 * 基础任务
 *
 * 实现getName和exec即可
 */
public abstract class BasicTask implements Runnable {
    public abstract String getName();
    public abstract void exec();

    public void run(){
        finished = false;

        try {
            exec();
        }
        catch (Exception e){
            Logger.error(e);
        }

        finished = true;
    }

    protected boolean finished;
    protected String taskId;

    public boolean isFinished() {
        return finished;
    }

    public String getTaskId() {
        return taskId;
    }

    public void setTaskId(String taskId) {
        this.taskId = taskId;
    }

    public BasicTask(){
        this.taskId = BasicUtils.uuid();
        this.finished = false;
    }
}
